@extends('layouts.prize')
@section('pageTitle', '奖品管理')
@section('content')
    <div class="main-panel">
        <div class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card ">
                            <div class="content" id="tableContent">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="staticModal" tabindex="-1" role="dialog" aria-labelledby="buyprizeModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content edit">
                <form method="post" action="">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                    aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="modalName">购买奖品</h4>
                    </div>
                    <div class="modal-body">
                        <input type="hidden" value="1" name="goods_id" id="goodsId">
                        <div class="row">
                            <div class="col-sm-8 ">
                                <div class="row">
                                    <div class="">
                                        <div class="form-group">
                                            <label id="inputFieldName" class="col-sm-3 control-label">购买数量</label>
                                            <div class="col-sm-8 ">
                                                {{ csrf_field() }}
                                                <input class="form-control wx-input-money"
                                                       type="number"
                                                       number="true"
                                                       name="number"
                                                       placeholder="请输入数量"
                                                       datatype="/^10$|^[1-9][0-9]{0,3}$/"
                                                       id="inputFiled"
                                                >
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" class="btn btn-primary btn-submit">确定</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection
@section('style')
    <link rel="stylesheet" href="/css/admin/validform_style.css">
@endsection()
@section('script')
    <script src="/js/admin/Validform_v5.3.2_min.js"></script>
    <script src="/js/initValidform.js"></script>
    <script>
		function queryTable(type_code) {
			$.get('/web/goods/query?type_code=' + type_code, function (res) {
				$('#tableContent').html(res);
			});
		}
		$(document).ready(function () {
			queryTable('');
		})

        $(document).on('click', '.operate-btn', function () {
            var goodsId = $(this).closest('.operate-group').attr('id');
            if ($(this).hasClass('buy')) {
                $('#staticModal').find('#goodsId').val(goodsId);
                // $('#staticModal').find('#inputFiled').val('');
                $('#staticModal').find('form').attr('action', '/web/goods/buy');
                $('#staticModal').find('#modalName').text('购买奖品');
                $('#staticModal').find('#inputFieldName').text('购买奖品数量');
                $('#staticModal').modal();
                initValidform($('#staticModal').find('form'));
            }
        });
        function initValidform(formObj) {
            return formObj.Validform({
                btnSubmit: ".btn-submit",
                postonce: true,
                ajaxPost: true,
                beforeSubmit: function (curform) {
                    var goods_num = parseInt($(curform).find('#inputFiled').val());
                    if( goods_num <= 0 ) {
                        alert('请输入有效数量');
                        return false;
                    }
                },
                callback: function (data) {
                    console.log(data);
                    if (data.code == 0) {
                        location.href = data.result;
                    } else {
                        utils.showNotification(data.result, 3);
                    }
                }
            });
        }
    </script>
@endsection()
